{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:36:35.700053Z",
     "start_time": "2021-11-13T07:36:35.269180Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>地区</th>\n",
       "      <th>服务分类</th>\n",
       "      <th>销售额</th>\n",
       "      <th>利润</th>\n",
       "      <th>年份</th>\n",
       "      <th>季度</th>\n",
       "      <th>年份/季度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Cote d'Ivoire</td>\n",
       "      <td>Abidjan</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>656.96</td>\n",
       "      <td>6.57</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Madagascar</td>\n",
       "      <td>Antananarivo</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>875.94</td>\n",
       "      <td>-70.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Rwanda</td>\n",
       "      <td>Kigali</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>258.35</td>\n",
       "      <td>18.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>Harare</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>875.62</td>\n",
       "      <td>-35.02</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-02</td>\n",
       "      <td>Ethiopia</td>\n",
       "      <td>Addis Ababa</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>509.93</td>\n",
       "      <td>10.20</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期             国家            城市       地区         服务分类     销售额  \\\n",
       "0 2017-01-01  Cote d'Ivoire       Abidjan  Western   Commercial  656.96   \n",
       "1 2017-01-01     Madagascar  Antananarivo  Eastern       Public  875.94   \n",
       "2 2017-01-01         Rwanda        Kigali  Eastern       Public  258.35   \n",
       "3 2017-01-01       Zimbabwe        Harare  Eastern  Residential  875.62   \n",
       "4 2017-01-02       Ethiopia   Addis Ababa  Eastern  Residential  509.93   \n",
       "\n",
       "      利润    年份 季度   年份/季度  \n",
       "0   6.57  2017  1  2017/1  \n",
       "1 -70.08  2017  1  2017/1  \n",
       "2  18.08  2017  1  2017/1  \n",
       "3 -35.02  2017  1  2017/1  \n",
       "4  10.20  2017  1  2017/1  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "SalesData = pd.read_excel('data/国家销售情况.xlsx')\n",
    "# 将日期改为年份/季度，并且增加年份和季度字段\n",
    "# 将日期转换为时间类型\n",
    "SalesData['日期'] = pd.to_datetime(SalesData['日期'])\n",
    "\n",
    "# 1、增加年份字段\n",
    "SalesData['年份'] = (SalesData['日期'].dt.year).apply(str)\n",
    "\n",
    "# 增加季度字段\n",
    "SalesData['季度'] = (SalesData['日期'].dt.quarter).apply(str)\n",
    "\n",
    "SalesData['年份/季度'] = SalesData['年份'].str.cat(SalesData['季度'],sep='/')\n",
    "\n",
    "SalesData.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:37:36.091907Z",
     "start_time": "2021-11-13T07:37:36.067970Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>地区</th>\n",
       "      <th>服务分类</th>\n",
       "      <th>销售额</th>\n",
       "      <th>利润</th>\n",
       "      <th>年份</th>\n",
       "      <th>季度</th>\n",
       "      <th>年份/季度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Cote d'Ivoire</td>\n",
       "      <td>Abidjan</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>656.96</td>\n",
       "      <td>6.57</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Madagascar</td>\n",
       "      <td>Antananarivo</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>875.94</td>\n",
       "      <td>-70.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Rwanda</td>\n",
       "      <td>Kigali</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>258.35</td>\n",
       "      <td>18.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>Harare</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>875.62</td>\n",
       "      <td>-35.02</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-02</td>\n",
       "      <td>Ethiopia</td>\n",
       "      <td>Addis Ababa</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>509.93</td>\n",
       "      <td>10.20</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-01-03</td>\n",
       "      <td>Chad</td>\n",
       "      <td>N'Djamena</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>443.13</td>\n",
       "      <td>4.43</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-01-03</td>\n",
       "      <td>Malawi</td>\n",
       "      <td>Blantyre</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>651.78</td>\n",
       "      <td>19.55</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-01-03</td>\n",
       "      <td>Mauritius</td>\n",
       "      <td>Port Louis</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>896.64</td>\n",
       "      <td>-62.76</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-01-04</td>\n",
       "      <td>Sao Tome and Principe</td>\n",
       "      <td>Sao Tome</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>226.92</td>\n",
       "      <td>13.62</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Burundi</td>\n",
       "      <td>Bujumbura</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>928.07</td>\n",
       "      <td>74.25</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Cameroon</td>\n",
       "      <td>Yaoundé</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Public</td>\n",
       "      <td>77.41</td>\n",
       "      <td>3.87</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Cote d'Ivoire</td>\n",
       "      <td>Yamoussoukro</td>\n",
       "      <td>Western</td>\n",
       "      <td>Public</td>\n",
       "      <td>263.65</td>\n",
       "      <td>10.55</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Nigeria</td>\n",
       "      <td>Lagos</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>950.83</td>\n",
       "      <td>-47.54</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Senegal</td>\n",
       "      <td>Dakar</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>252.01</td>\n",
       "      <td>22.68</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>South Africa</td>\n",
       "      <td>Cape Town</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>173.98</td>\n",
       "      <td>-10.44</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>Benin</td>\n",
       "      <td>Porto-Novo</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>384.51</td>\n",
       "      <td>34.61</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>Sierra Leone</td>\n",
       "      <td>Freetown</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>301.55</td>\n",
       "      <td>-6.03</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2017-01-07</td>\n",
       "      <td>Equatorial Guinea</td>\n",
       "      <td>Malabo</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>876.78</td>\n",
       "      <td>-43.84</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2017-01-07</td>\n",
       "      <td>Western Sahara</td>\n",
       "      <td>Dakhla</td>\n",
       "      <td>Northern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>235.84</td>\n",
       "      <td>-2.36</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2017-01-08</td>\n",
       "      <td>Nigeria</td>\n",
       "      <td>Kano</td>\n",
       "      <td>Western</td>\n",
       "      <td>Public</td>\n",
       "      <td>580.55</td>\n",
       "      <td>-40.64</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2017-01-08</td>\n",
       "      <td>Sudan</td>\n",
       "      <td>Khartoum</td>\n",
       "      <td>Northern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>218.64</td>\n",
       "      <td>17.49</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2017-01-09</td>\n",
       "      <td>Algeria</td>\n",
       "      <td>Algiers</td>\n",
       "      <td>Northern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>906.30</td>\n",
       "      <td>9.06</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>Eritrea</td>\n",
       "      <td>Asmara</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>791.98</td>\n",
       "      <td>7.92</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>Libya</td>\n",
       "      <td>Tripoli</td>\n",
       "      <td>Northern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>643.73</td>\n",
       "      <td>45.06</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>Niger</td>\n",
       "      <td>Niamey</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>3.30</td>\n",
       "      <td>-0.03</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>Togo</td>\n",
       "      <td>Lome</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>326.97</td>\n",
       "      <td>22.89</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2017-01-12</td>\n",
       "      <td>Guinea-Bissau</td>\n",
       "      <td>Bissau</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>28.16</td>\n",
       "      <td>0.28</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2017-01-12</td>\n",
       "      <td>United Republic of Tanzania</td>\n",
       "      <td>Dar es Salaam</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>232.27</td>\n",
       "      <td>-2.32</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2017-01-13</td>\n",
       "      <td>Ghana</td>\n",
       "      <td>Kumasi</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>83.11</td>\n",
       "      <td>8.31</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2017-01-14</td>\n",
       "      <td>Botswana</td>\n",
       "      <td>Gaborone</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>660.12</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>863</th>\n",
       "      <td>2020-02-11</td>\n",
       "      <td>Mali</td>\n",
       "      <td>Bamako</td>\n",
       "      <td>Western</td>\n",
       "      <td>Public</td>\n",
       "      <td>93.81</td>\n",
       "      <td>-2.81</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>864</th>\n",
       "      <td>2020-02-12</td>\n",
       "      <td>Central African Republic</td>\n",
       "      <td>Bangui</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Public</td>\n",
       "      <td>341.86</td>\n",
       "      <td>13.67</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>865</th>\n",
       "      <td>2020-02-12</td>\n",
       "      <td>Kenya</td>\n",
       "      <td>Nairobi</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>836.00</td>\n",
       "      <td>16.72</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>866</th>\n",
       "      <td>2020-02-12</td>\n",
       "      <td>Malawi</td>\n",
       "      <td>Lilongwe</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>954.46</td>\n",
       "      <td>-19.09</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>867</th>\n",
       "      <td>2020-02-13</td>\n",
       "      <td>Djibouti</td>\n",
       "      <td>Djibouti</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>740.24</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>868</th>\n",
       "      <td>2020-02-16</td>\n",
       "      <td>South Sudan</td>\n",
       "      <td>Juba</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>374.57</td>\n",
       "      <td>22.47</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>869</th>\n",
       "      <td>2020-02-17</td>\n",
       "      <td>Equatorial Guinea</td>\n",
       "      <td>Malabo</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Public</td>\n",
       "      <td>293.14</td>\n",
       "      <td>29.31</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>870</th>\n",
       "      <td>2020-02-19</td>\n",
       "      <td>Cameroon</td>\n",
       "      <td>Yaoundé</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Public</td>\n",
       "      <td>293.91</td>\n",
       "      <td>-5.88</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>871</th>\n",
       "      <td>2020-02-22</td>\n",
       "      <td>Nigeria</td>\n",
       "      <td>Lagos</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>91.77</td>\n",
       "      <td>4.59</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>872</th>\n",
       "      <td>2020-02-22</td>\n",
       "      <td>Uganda</td>\n",
       "      <td>Kampala</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>163.23</td>\n",
       "      <td>16.32</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>873</th>\n",
       "      <td>2020-02-24</td>\n",
       "      <td>Botswana</td>\n",
       "      <td>Gaborone</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>117.65</td>\n",
       "      <td>3.53</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>2020-02-25</td>\n",
       "      <td>Burkina Faso</td>\n",
       "      <td>Ouagadougou</td>\n",
       "      <td>Western</td>\n",
       "      <td>Public</td>\n",
       "      <td>941.90</td>\n",
       "      <td>-47.10</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>875</th>\n",
       "      <td>2020-02-26</td>\n",
       "      <td>South Africa</td>\n",
       "      <td>Durban</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>475.90</td>\n",
       "      <td>23.80</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>876</th>\n",
       "      <td>2020-02-27</td>\n",
       "      <td>Democratic Republic of the Congo</td>\n",
       "      <td>Lubumbashi</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>72.89</td>\n",
       "      <td>6.56</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>877</th>\n",
       "      <td>2020-02-27</td>\n",
       "      <td>Sudan</td>\n",
       "      <td>Khartoum</td>\n",
       "      <td>Northern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>413.83</td>\n",
       "      <td>-33.11</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>878</th>\n",
       "      <td>2020-02-28</td>\n",
       "      <td>Mauritius</td>\n",
       "      <td>Port Louis</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>859.44</td>\n",
       "      <td>68.76</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>879</th>\n",
       "      <td>2020-03-02</td>\n",
       "      <td>Sao Tome and Principe</td>\n",
       "      <td>Sao Tome</td>\n",
       "      <td>Middle</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>330.17</td>\n",
       "      <td>-23.11</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>880</th>\n",
       "      <td>2020-03-03</td>\n",
       "      <td>Sierra Leone</td>\n",
       "      <td>Freetown</td>\n",
       "      <td>Western</td>\n",
       "      <td>Public</td>\n",
       "      <td>400.61</td>\n",
       "      <td>-20.03</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>881</th>\n",
       "      <td>2020-03-07</td>\n",
       "      <td>Senegal</td>\n",
       "      <td>Dakar</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>134.83</td>\n",
       "      <td>6.74</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>882</th>\n",
       "      <td>2020-03-08</td>\n",
       "      <td>Swaziland</td>\n",
       "      <td>Mbabane</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>322.28</td>\n",
       "      <td>-9.67</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>883</th>\n",
       "      <td>2020-03-10</td>\n",
       "      <td>Lesotho</td>\n",
       "      <td>Maseru</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Public</td>\n",
       "      <td>318.66</td>\n",
       "      <td>25.49</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>884</th>\n",
       "      <td>2020-03-11</td>\n",
       "      <td>Madagascar</td>\n",
       "      <td>Antananarivo</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>309.23</td>\n",
       "      <td>30.92</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>885</th>\n",
       "      <td>2020-03-12</td>\n",
       "      <td>Cote d'Ivoire</td>\n",
       "      <td>Yamoussoukro</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>385.31</td>\n",
       "      <td>3.85</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886</th>\n",
       "      <td>2020-03-12</td>\n",
       "      <td>Zambia</td>\n",
       "      <td>Lusaka</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>748.72</td>\n",
       "      <td>7.49</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>2020-03-13</td>\n",
       "      <td>Ghana</td>\n",
       "      <td>Accra</td>\n",
       "      <td>Western</td>\n",
       "      <td>Public</td>\n",
       "      <td>400.33</td>\n",
       "      <td>28.02</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>2020-03-24</td>\n",
       "      <td>Ethiopia</td>\n",
       "      <td>Addis Ababa</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>302.99</td>\n",
       "      <td>9.09</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889</th>\n",
       "      <td>2020-03-25</td>\n",
       "      <td>Liberia</td>\n",
       "      <td>Monrovia</td>\n",
       "      <td>Western</td>\n",
       "      <td>Residential</td>\n",
       "      <td>242.50</td>\n",
       "      <td>24.25</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>890</th>\n",
       "      <td>2020-03-25</td>\n",
       "      <td>Mozambique</td>\n",
       "      <td>Maputo</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>806.47</td>\n",
       "      <td>80.65</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>891</th>\n",
       "      <td>2020-03-25</td>\n",
       "      <td>South Africa</td>\n",
       "      <td>Johannesburg</td>\n",
       "      <td>Southern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>55.47</td>\n",
       "      <td>3.33</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>892</th>\n",
       "      <td>2020-03-27</td>\n",
       "      <td>Guinea-Bissau</td>\n",
       "      <td>Bissau</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>623.03</td>\n",
       "      <td>-6.23</td>\n",
       "      <td>2020</td>\n",
       "      <td>1</td>\n",
       "      <td>2020/1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>389 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期                                国家             城市        地区  \\\n",
       "0   2017-01-01                     Cote d'Ivoire        Abidjan   Western   \n",
       "1   2017-01-01                        Madagascar   Antananarivo   Eastern   \n",
       "2   2017-01-01                            Rwanda         Kigali   Eastern   \n",
       "3   2017-01-01                          Zimbabwe         Harare   Eastern   \n",
       "4   2017-01-02                          Ethiopia    Addis Ababa   Eastern   \n",
       "5   2017-01-03                              Chad      N'Djamena    Middle   \n",
       "6   2017-01-03                            Malawi       Blantyre   Eastern   \n",
       "7   2017-01-03                         Mauritius     Port Louis   Eastern   \n",
       "8   2017-01-04             Sao Tome and Principe       Sao Tome    Middle   \n",
       "9   2017-01-05                           Burundi      Bujumbura   Eastern   \n",
       "10  2017-01-05                          Cameroon        Yaoundé    Middle   \n",
       "11  2017-01-05                     Cote d'Ivoire   Yamoussoukro   Western   \n",
       "12  2017-01-05                           Nigeria          Lagos   Western   \n",
       "13  2017-01-05                           Senegal          Dakar   Western   \n",
       "14  2017-01-05                      South Africa      Cape Town  Southern   \n",
       "15  2017-01-06                             Benin     Porto-Novo   Western   \n",
       "16  2017-01-06                      Sierra Leone       Freetown   Western   \n",
       "17  2017-01-07                 Equatorial Guinea         Malabo    Middle   \n",
       "18  2017-01-07                    Western Sahara         Dakhla  Northern   \n",
       "19  2017-01-08                           Nigeria           Kano   Western   \n",
       "20  2017-01-08                             Sudan       Khartoum  Northern   \n",
       "21  2017-01-09                           Algeria        Algiers  Northern   \n",
       "22  2017-01-10                           Eritrea         Asmara   Eastern   \n",
       "23  2017-01-10                             Libya        Tripoli  Northern   \n",
       "24  2017-01-10                             Niger         Niamey   Western   \n",
       "25  2017-01-10                              Togo           Lome   Western   \n",
       "26  2017-01-12                     Guinea-Bissau         Bissau   Western   \n",
       "27  2017-01-12       United Republic of Tanzania  Dar es Salaam   Eastern   \n",
       "28  2017-01-13                             Ghana         Kumasi   Western   \n",
       "29  2017-01-14                          Botswana       Gaborone  Southern   \n",
       "..         ...                               ...            ...       ...   \n",
       "863 2020-02-11                              Mali         Bamako   Western   \n",
       "864 2020-02-12          Central African Republic         Bangui    Middle   \n",
       "865 2020-02-12                             Kenya        Nairobi   Eastern   \n",
       "866 2020-02-12                            Malawi       Lilongwe   Eastern   \n",
       "867 2020-02-13                          Djibouti       Djibouti   Eastern   \n",
       "868 2020-02-16                       South Sudan           Juba   Eastern   \n",
       "869 2020-02-17                 Equatorial Guinea         Malabo    Middle   \n",
       "870 2020-02-19                          Cameroon        Yaoundé    Middle   \n",
       "871 2020-02-22                           Nigeria          Lagos   Western   \n",
       "872 2020-02-22                            Uganda        Kampala   Eastern   \n",
       "873 2020-02-24                          Botswana       Gaborone  Southern   \n",
       "874 2020-02-25                      Burkina Faso    Ouagadougou   Western   \n",
       "875 2020-02-26                      South Africa         Durban  Southern   \n",
       "876 2020-02-27  Democratic Republic of the Congo     Lubumbashi    Middle   \n",
       "877 2020-02-27                             Sudan       Khartoum  Northern   \n",
       "878 2020-02-28                         Mauritius     Port Louis   Eastern   \n",
       "879 2020-03-02             Sao Tome and Principe       Sao Tome    Middle   \n",
       "880 2020-03-03                      Sierra Leone       Freetown   Western   \n",
       "881 2020-03-07                           Senegal          Dakar   Western   \n",
       "882 2020-03-08                         Swaziland        Mbabane  Southern   \n",
       "883 2020-03-10                           Lesotho         Maseru  Southern   \n",
       "884 2020-03-11                        Madagascar   Antananarivo   Eastern   \n",
       "885 2020-03-12                     Cote d'Ivoire   Yamoussoukro   Western   \n",
       "886 2020-03-12                            Zambia         Lusaka   Eastern   \n",
       "887 2020-03-13                             Ghana          Accra   Western   \n",
       "888 2020-03-24                          Ethiopia    Addis Ababa   Eastern   \n",
       "889 2020-03-25                           Liberia       Monrovia   Western   \n",
       "890 2020-03-25                        Mozambique         Maputo   Eastern   \n",
       "891 2020-03-25                      South Africa   Johannesburg  Southern   \n",
       "892 2020-03-27                     Guinea-Bissau         Bissau   Western   \n",
       "\n",
       "            服务分类     销售额     利润    年份 季度   年份/季度  \n",
       "0     Commercial  656.96   6.57  2017  1  2017/1  \n",
       "1         Public  875.94 -70.08  2017  1  2017/1  \n",
       "2         Public  258.35  18.08  2017  1  2017/1  \n",
       "3    Residential  875.62 -35.02  2017  1  2017/1  \n",
       "4    Residential  509.93  10.20  2017  1  2017/1  \n",
       "5     Commercial  443.13   4.43  2017  1  2017/1  \n",
       "6    Residential  651.78  19.55  2017  1  2017/1  \n",
       "7         Public  896.64 -62.76  2017  1  2017/1  \n",
       "8     Commercial  226.92  13.62  2017  1  2017/1  \n",
       "9     Commercial  928.07  74.25  2017  1  2017/1  \n",
       "10        Public   77.41   3.87  2017  1  2017/1  \n",
       "11        Public  263.65  10.55  2017  1  2017/1  \n",
       "12   Residential  950.83 -47.54  2017  1  2017/1  \n",
       "13    Commercial  252.01  22.68  2017  1  2017/1  \n",
       "14   Residential  173.98 -10.44  2017  1  2017/1  \n",
       "15   Residential  384.51  34.61  2017  1  2017/1  \n",
       "16   Residential  301.55  -6.03  2017  1  2017/1  \n",
       "17    Commercial  876.78 -43.84  2017  1  2017/1  \n",
       "18   Residential  235.84  -2.36  2017  1  2017/1  \n",
       "19        Public  580.55 -40.64  2017  1  2017/1  \n",
       "20   Residential  218.64  17.49  2017  1  2017/1  \n",
       "21   Residential  906.30   9.06  2017  1  2017/1  \n",
       "22    Commercial  791.98   7.92  2017  1  2017/1  \n",
       "23   Residential  643.73  45.06  2017  1  2017/1  \n",
       "24   Residential    3.30  -0.03  2017  1  2017/1  \n",
       "25   Residential  326.97  22.89  2017  1  2017/1  \n",
       "26    Commercial   28.16   0.28  2017  1  2017/1  \n",
       "27   Residential  232.27  -2.32  2017  1  2017/1  \n",
       "28   Residential   83.11   8.31  2017  1  2017/1  \n",
       "29    Commercial  660.12   0.00  2017  1  2017/1  \n",
       "..           ...     ...    ...   ... ..     ...  \n",
       "863       Public   93.81  -2.81  2020  1  2020/1  \n",
       "864       Public  341.86  13.67  2020  1  2020/1  \n",
       "865  Residential  836.00  16.72  2020  1  2020/1  \n",
       "866       Public  954.46 -19.09  2020  1  2020/1  \n",
       "867       Public  740.24   0.00  2020  1  2020/1  \n",
       "868  Residential  374.57  22.47  2020  1  2020/1  \n",
       "869       Public  293.14  29.31  2020  1  2020/1  \n",
       "870       Public  293.91  -5.88  2020  1  2020/1  \n",
       "871   Commercial   91.77   4.59  2020  1  2020/1  \n",
       "872  Residential  163.23  16.32  2020  1  2020/1  \n",
       "873   Commercial  117.65   3.53  2020  1  2020/1  \n",
       "874       Public  941.90 -47.10  2020  1  2020/1  \n",
       "875  Residential  475.90  23.80  2020  1  2020/1  \n",
       "876   Commercial   72.89   6.56  2020  1  2020/1  \n",
       "877   Commercial  413.83 -33.11  2020  1  2020/1  \n",
       "878       Public  859.44  68.76  2020  1  2020/1  \n",
       "879   Commercial  330.17 -23.11  2020  1  2020/1  \n",
       "880       Public  400.61 -20.03  2020  1  2020/1  \n",
       "881   Commercial  134.83   6.74  2020  1  2020/1  \n",
       "882   Commercial  322.28  -9.67  2020  1  2020/1  \n",
       "883       Public  318.66  25.49  2020  1  2020/1  \n",
       "884  Residential  309.23  30.92  2020  1  2020/1  \n",
       "885   Commercial  385.31   3.85  2020  1  2020/1  \n",
       "886   Commercial  748.72   7.49  2020  1  2020/1  \n",
       "887       Public  400.33  28.02  2020  1  2020/1  \n",
       "888  Residential  302.99   9.09  2020  1  2020/1  \n",
       "889  Residential  242.50  24.25  2020  1  2020/1  \n",
       "890   Commercial  806.47  80.65  2020  1  2020/1  \n",
       "891  Residential   55.47   3.33  2020  1  2020/1  \n",
       "892   Commercial  623.03  -6.23  2020  1  2020/1  \n",
       "\n",
       "[389 rows x 10 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、将各个年份第1季度的各个地区，国家，服务分类的分别提取出来\n",
    "data = SalesData[SalesData['季度']=='1']\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:37:58.494548Z",
     "start_time": "2021-11-13T07:37:58.472046Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "年份    地区      \n",
       "2017  Eastern     -31.39\n",
       "      Middle      293.39\n",
       "      Northern    165.14\n",
       "      Southern    -62.89\n",
       "      Western     184.98\n",
       "2018  Eastern     175.83\n",
       "      Middle       -7.37\n",
       "      Northern    275.23\n",
       "      Southern    412.36\n",
       "      Western     -99.38\n",
       "2019  Eastern      45.95\n",
       "      Middle      394.69\n",
       "      Northern    101.16\n",
       "      Southern     77.29\n",
       "      Western    -135.50\n",
       "2020  Eastern     347.48\n",
       "      Middle      162.34\n",
       "      Northern   -108.14\n",
       "      Southern     58.63\n",
       "      Western     140.60\n",
       "Name: 利润, dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_profit = data.groupby(['年份','地区']).sum()['利润']\n",
    "yearoneSaleArea_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:38:27.909471Z",
     "start_time": "2021-11-13T07:38:27.903487Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ -31.39,  293.39,  165.14,  -62.89,  184.98,  175.83,   -7.37,\n",
       "        275.23,  412.36,  -99.38,   45.95,  394.69,  101.16,   77.29,\n",
       "       -135.5 ,  347.48,  162.34, -108.14,   58.63,  140.6 ])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2017-2020 [Eastern,Middle,Northern,Southern,Western]\n",
    "yearoneSaleArea_profit.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T08:08:00.274888Z",
     "start_time": "2021-11-13T08:08:00.267926Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20,)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_profit.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:38:39.045533Z",
     "start_time": "2021-11-13T07:38:39.033543Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 347.48,  162.34, -108.14,   58.63,  140.6 ])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_test = yearoneSaleArea_profit.values[-5:]\n",
    "x_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:38:52.838535Z",
     "start_time": "2021-11-13T07:38:52.832552Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ -31.39,  293.39,  165.14,  -62.89,  184.98,  175.83,   -7.37,\n",
       "        275.23,  412.36,  -99.38,   45.95,  394.69,  101.16,   77.29,\n",
       "       -135.5 ])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_sales_x_train = yearoneSaleArea_profit.values[:-5]\n",
    "yearoneSaleArea_sales_x_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:39:10.645582Z",
     "start_time": "2021-11-13T07:39:10.632515Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 175.83,   -7.37,  275.23,  412.36,  -99.38,   45.95,  394.69,\n",
       "        101.16,   77.29, -135.5 ,  347.48,  162.34, -108.14,   58.63,\n",
       "        140.6 ])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_sales_y_train = yearoneSaleArea_profit.values[5:]\n",
    "yearoneSaleArea_sales_y_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:39:25.986045Z",
     "start_time": "2021-11-13T07:39:25.118126Z"
    }
   },
   "outputs": [],
   "source": [
    "# 标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "# 特征值标准化 \n",
    "std_x = StandardScaler()\n",
    "x_train = std_x.fit_transform(yearoneSaleArea_sales_x_train.reshape(-1,1))\n",
    "x_test = std_x.transform(x_test.reshape(-1,1))\n",
    "\n",
    "# 目标值标准化\n",
    "std_y = StandardScaler()\n",
    "y_train = std_y.fit_transform(yearoneSaleArea_sales_y_train.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:39:29.457349Z",
     "start_time": "2021-11-13T07:39:29.449370Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据标准化之前： [[ -31.39]\n",
      " [ 293.39]\n",
      " [ 165.14]\n",
      " [ -62.89]\n",
      " [ 184.98]\n",
      " [ 175.83]\n",
      " [  -7.37]\n",
      " [ 275.23]\n",
      " [ 412.36]\n",
      " [ -99.38]\n",
      " [  45.95]\n",
      " [ 394.69]\n",
      " [ 101.16]\n",
      " [  77.29]\n",
      " [-135.5 ]]\n",
      "数据标准化之后： [[-0.9025631 ]\n",
      " [ 1.04272684]\n",
      " [ 0.27456551]\n",
      " [-1.0912343 ]\n",
      " [ 0.39339842]\n",
      " [ 0.33859393]\n",
      " [-0.75869382]\n",
      " [ 0.93395639]\n",
      " [ 1.75530503]\n",
      " [-1.30979342]\n",
      " [-0.43933038]\n",
      " [ 1.64946947]\n",
      " [-0.10864666]\n",
      " [-0.25161751]\n",
      " [-1.5261364 ]]\n"
     ]
    }
   ],
   "source": [
    "print(\"数据标准化之前：\",yearoneSaleArea_sales_x_train.reshape(-1,1))\n",
    "print(\"数据标准化之后：\",x_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:39:37.330373Z",
     "start_time": "2021-11-13T07:39:37.252302Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SGDRegressor(max_iter=500)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import SGDRegressor\n",
    "sgd = SGDRegressor(max_iter=500)\n",
    "\n",
    "sgd.fit(x_train,y_train.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:42:34.396334Z",
     "start_time": "2021-11-13T07:42:34.391347Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "参数w:\n",
      " [-0.10469236] [-0.00228953] \n",
      "\n",
      "\n",
      "得到公式为：y=wx+b,其中w=[-0.10469236],b=[-0.00228953]\n"
     ]
    }
   ],
   "source": [
    "print(\"参数w:\\n\",sgd.coef_,sgd.intercept_,\"\\n\\n\")\n",
    "print('得到公式为：y=wx+b,其中w=%s,b=%s'%(sgd.coef_,sgd.intercept_))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:43:02.152839Z",
     "start_time": "2021-11-13T07:43:02.146826Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021预测的利润(标准化):\n",
      " [-0.14537281 -0.02927867  0.1403289   0.03575387 -0.01564635]\n"
     ]
    }
   ],
   "source": [
    "# 预测房子价格(标准值)\n",
    "y_predict = sgd.predict(x_test)\n",
    "print(\"2021预测的利润(标准化):\\n\",y_predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:43:02.945426Z",
     "start_time": "2021-11-13T07:43:02.936451Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021预测的利润为:\n",
      " [ 97.98569254 117.75810997 146.64459299 128.83403852 120.0798792 ]\n"
     ]
    }
   ],
   "source": [
    "# 预测房子的价格(正常值)\n",
    "value_predict = std_y.inverse_transform(y_predict)\n",
    "\n",
    "print(\"2021预测的利润为:\\n\",value_predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
